#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,a[N];
int red[N],blue[N];
int ans;
void dfs(int x,int rt,int bt){
    if(x > n){
        int r = 0,b = 0;
        for(int i = 1;i <= rt;i++){
            if(a[red[i-1]] == a[red[i]]) r += a[red[i]];
        }
        for(int i = 1;i <= bt;i++){
            if(a[blue[i-1]] == a[blue[i]]) b += a[blue[i]];
        }
        ans = max(ans,r+b);
        return;
    }
    red[rt+1] = x;
    dfs(x+1,rt+1,bt);
    blue[bt+1] = x;
    dfs(x+1,rt,bt+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;cin >> T;
    while(T--){
        cin >> n;
        ans = 0;
        for(int i = 1;i <= n;i++) cin >> a[i];
        dfs(1,0,0);
        cout << ans << "\n";
    }
    return 0;
}
